package com.woniuxy.woniuhis.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.woniuxy.woniuhis.entity.GodownItem;
import com.woniuxy.woniuhis.exception.MedicineServiceException;
import com.woniuxy.woniuhis.service.GodownEntryService;
import com.woniuxy.woniuhis.service.MedicineCostService;
import com.woniuxy.woniuhis.service.OrderCartService;
import com.woniuxy.woniuhis.service.OrderService;
import com.woniuxy.woniuhis.service.PharmacyService;
import com.woniuxy.woniuhis.util.ResponseInfo;


@Controller
public class GodownEntryController {

    @Autowired
    OrderCartService orderCartService;
    
    @Autowired
    MedicineCostService medicineCostService;
    
    @Autowired
    PharmacyService pharmacyService;
    
    @Autowired
    OrderService orderService;
    
    @Autowired
    GodownEntryService godownEntryService;
    /**
     * @param req
     * @return
     * 查看详单
     */
    
    @RequestMapping("makeItem")
    @ResponseBody
    public ResponseInfo makeItemController(HttpServletRequest req) {
    	
    	String listId = req.getParameter("listId");
    	System.out.println(listId); 
    	
    	GodownItem godownItem = new GodownItem();
    	godownItem.setListId(listId);
		
    	try {
    		
    		List<GodownItem> entrys = godownEntryService.findGodownItemByListId(godownItem);
    		
    		
    		ResponseInfo responseInfo = new ResponseInfo();
    		responseInfo.setData(entrys);
    		responseInfo.setMsg("查找成功");
    		responseInfo.setState(200);
    		
    		

    		return responseInfo;
		} catch (MedicineServiceException e) {
			System.out.println("makeItemController错误");
			e.printStackTrace();
			
        	ResponseInfo responseInfo = new ResponseInfo();
        	responseInfo.setMsg("makeItemController服务方法错误");
        	

    		return responseInfo;
		}  catch (Exception e) {
			System.out.println("其他错误");
			e.printStackTrace();
			
        	ResponseInfo responseInfo = new ResponseInfo();
        	responseInfo.setMsg("输入错误");
        	responseInfo.setState(500);

    		return responseInfo;
		}
    }
    
    /**
     * @param req
     * @return
     * 查看详单
     */
    
    @RequestMapping("godown")
    @ResponseBody
    public ModelAndView TogodownController(HttpServletRequest req) {
    	
    	String listId = req.getParameter("listId");
    	System.out.println(listId); 
    	
    	GodownItem godownItem = new GodownItem();
    	godownItem.setListId(listId);
		
    	try {
    		
    		List<GodownItem> entrys = godownEntryService.findGodownItemByListId(godownItem);
    		
    		
    		ResponseInfo responseInfo = new ResponseInfo();
    		responseInfo.setData(entrys);
    		responseInfo.setMsg("添加成功");
    		responseInfo.setState(200);
    		
    		ModelAndView mv = new ModelAndView();
    		mv.setViewName("views/storage/item.html");
    		mv.addObject("info", responseInfo);
    		
        	return mv;
		} catch (MedicineServiceException e) {
			System.out.println("createController错误");
			e.printStackTrace();
			
        	ResponseInfo responseInfo = new ResponseInfo();
        	responseInfo.setMsg("createController服务方法错误");
        	

    		ModelAndView mv = new ModelAndView();
    		mv.setViewName("views/storage/item.html");
    		mv.addObject("info", responseInfo);
    		
        	return mv;
		}  catch (Exception e) {
			System.out.println("其他错误");
			e.printStackTrace();
			
        	ResponseInfo responseInfo = new ResponseInfo();
        	responseInfo.setMsg("输入错误");
        	responseInfo.setState(500);

    		ModelAndView mv = new ModelAndView();
    		mv.setViewName("views/storage/item.html");
    		mv.addObject("info", responseInfo);
    		
        	return mv;
		}
    }
  
	
}
